package com.example.recyclerviewdemo;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.recyclerviewdemo.adapter.StringAdapter;
import com.google.android.material.appbar.MaterialToolbar;

import java.util.List;

public class RvBasicUseActivity extends BaseActivity {

    private MaterialToolbar materialToolbar;
    private RecyclerView rvText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rv_basic_use);
        initView();
        back(materialToolbar);

        List<String> strings = getStrings();
        //获取适配器实例
        StringAdapter stringAdapter = new StringAdapter(getStrings());
        stringAdapter.setOnItemClickListener((view, position) -> showMsg(strings.get(position)));
        //子控件点击事件
        stringAdapter.setOnItemChildClickListener((view, position) -> {
            showMsg(strings.get(position)+"按钮");
        });
        //配置适配器
        rvText.setAdapter(stringAdapter);
        //配置布局管理器
        rvText.setLayoutManager(new LinearLayoutManager(this));
    }

    private void initView() {
        materialToolbar = (MaterialToolbar) findViewById(R.id.materialToolbar);
        rvText = (RecyclerView) findViewById(R.id.rv_text);
    }
}